package com.woniu.p2p.behindServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.p2p.behindService.UserChargeService;
import com.woniu.p2p.entity.User;
import com.woniu.p2p.entity.UserCharge;
import com.woniu.p2p.mapper.UserChargeMapper;
import com.woniu.p2p.mapper.UserMapper;
import com.woniu.p2p.vo.UserChargeRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class UserChargeServiceImpl implements UserChargeService {

    @Autowired
    UserChargeMapper userChargeMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    public PageInfo<UserChargeRecordVo> findAllUserChargeByDateAndTypeAndKeyword(Date predate, Date nextdate, String chargetype, String chargekeyword, Integer start, Integer num) {
        PageHelper.startPage(start,num);
        List<UserChargeRecordVo> list=null;
        java.sql.Date date=null;
        java.sql.Date date1=null;
        if(predate!=null && nextdate==null){
             date = new java.sql.Date(predate.getTime());
            list = userChargeMapper.findAllUserChargeByTypeAndKeyword(date, null, chargekeyword, chargetype);
        }
        if(nextdate!=null && predate==null){
             date1 = new java.sql.Date(nextdate.getTime());
            list = userChargeMapper.findAllUserChargeByTypeAndKeyword(null, date1, chargekeyword, chargetype);
        }
        if(predate!=null && nextdate!=null){
            date = new java.sql.Date(predate.getTime());
            date1 = new java.sql.Date(nextdate.getTime());
            list = userChargeMapper.findAllUserChargeByTypeAndKeyword(date, date1, chargekeyword, chargetype);
        }
        list = userChargeMapper.findAllUserChargeByTypeAndKeyword(predate, nextdate, chargekeyword, chargetype);
        PageInfo<UserChargeRecordVo> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public User findAllUserById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public UserCharge findAllUserCharge(Integer id) {
        return userChargeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<UserChargeRecordVo> findAllUserChaege(int[] id) {
        List<UserChargeRecordVo> list = userChargeMapper.findAllUserChargeById(id);
        return list;
    }
}
